<?php

if (!isset($_GET['gbpage'])) {
	$gbpage = 1;
} else {
	$gbpage = $_GET['gbpage'];
}

// $gbooks = new Led_Entity_Collection(0, 25);



if ($this->entity->gbid != 0) {

    $gb2 = $this->app->getEdo()->fetch($this->entity->gbid, 'ent_guestbook');

	$post = new Led_Entity_Collection(0, 27, $this->app->getLangid(), 2, $gb2->id, 40);
		
	
	if ($post->count()) {
		if ($post->size < ($this->entity->postsperpage * $gbpage)) {
			$sizedoesmatter = $post->count();
		} else {
			$sizedoesmatter = ($this->entity->postsperpage * $gbpage);
		}

	} else {
		$sizedoesmatter = 0;
	}

} 


$totalposts = $post->count();
$totalpages = (int) ($totalposts / $this->entity->postsperpage);
	
if ($totalposts % $this->entity->postsperpage > 0) {
	$totalpages = $totalpages + 1;
}

$this->entity->guestBookPages($gbpage, $totalpages);	

if ($totalposts) {
	
    $post->slice($this->entity->postsperpage * ($gbpage-1), $this->entity->postsperpage);
	
    foreach($post as $post2)
        print Led_Entity_Renderer::getInstance()->render($post2, 'retail');
    
    /*
	for ($laxuri = ($this->entity->postsperpage * ($gbpage-1) + 1); $laxuri <= $sizedoesmatter; $laxuri++) {
		$post2 = current($post_slice);
		$post2->render($version);
		next($post_slice);
	}
	*/
}

$this->entity->guestBookPages($gbpage, $totalpages);	
